package com.tanhua.server.service;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import com.tanhua.common.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

    @Service
    public class UserService {

        @Autowired
        private RSAService rsaService;

        /**
         * 通过公钥校验token，校验成功后返回用户id
         *
         * @param token
         * @return
         */
        public Long checkToken(String token) {
            Map<String, Object> map = JwtUtils.checkToken(token, this.rsaService.getPublicKey());
            if (CollUtil.isNotEmpty(map)) {
                return Convert.toLong(map.get("id"));
            }
            return null;
        }
    }
